package com.javasm.sale;

import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.javasm.gg.Goods;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.util.HashMap;

@TableName("sale_commodity_order")
public class CommodityOrder implements Serializable {

    @ExcelProperty("订单编号")
    private String orderId;

    @ExcelProperty("商品编号")
    private String gcode;

    @ExcelProperty("商品数量")
    private Integer num;

    @TableField("com_total_money")
    @ExcelProperty("总金额")
    private Double totalMoney;

    @TableField("com_one_money")
    @ExcelProperty("单价")
    private Double oneMoney;//单价

    private String createTime;

    private String updateTime;

    @ExcelProperty("失败原因")
    @TableField(exist = false)
    private String errorMsg="数据库保存失败";

    @TableField(exist = false)
    private Goods goodsInfo;

    public Goods getGoodsInfo() {
        return goodsInfo;
    }

    public void setGoodsInfo(Goods goodsInfo) {
        this.goodsInfo = goodsInfo;
    }

    public Double getOneMoney() {
        return oneMoney;
    }

    public void setOneMoney(Double oneMoney) {
        this.oneMoney = oneMoney;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public String getOrderId() {
        return orderId;
    }

    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }

    public String getGcode() {
        return gcode;
    }

    public void setGcode(String gcode) {
        this.gcode = gcode;
    }

    public Integer getNum() {
        return num;
    }

    public void setNum(Integer num) {
        this.num = num;
    }

    public Double getTotalMoney() {
        return totalMoney;
    }

    public void setTotalMoney(Double totalMoney) {
        this.totalMoney = totalMoney;
    }

    public String getCreateTime() {
        return createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    public String getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(String updateTime) {
        this.updateTime = updateTime;
    }




    public boolean check() {

        if(orderId==null)errorMsg="订单编号为空";
        if(gcode ==null)errorMsg="商品编号为空";
        if(num==null)errorMsg="商品数量为空";
        if(totalMoney==null)errorMsg="总金额为空";
        if(!"数据库保存失败".equals(errorMsg)){
            return false;
        }
        return true;

    }

    public boolean parse(HashMap<String, String> commodityMap) {
        String comId = commodityMap.get(this.getGcode());
        if(!StringUtils.hasLength(comId)){
            errorMsg="商品编号不存在";
            return false;
        }
        this.setGcode(comId);
        return true;


    }
}

